package com.cm.dao.impl;

import com.cm.dao.Emp;
import com.cm.entity.EmpEntity;
import com.cm.util.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class EmplDaoIMPL extends DButil implements Emp {
        Connection conn=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        public List<EmpEntity> getAllEmpEntity(){
            List<EmpEntity> list=new ArrayList<EmpEntity>();
            String sql="select * from employees";
            conn=getConn();
            try{
                pstmt=conn.prepareStatement(sql);
                rs=pstmt.executeQuery();
                while (rs.next()){
                    EmpEntity emp=new EmpEntity();
                    emp.setEmployee_id(rs.getInt("id"));
                    emp.setFirst_name(rs.getString("ename"));
                    emp.setLast_name(rs.getString("last"));
                    emp.setEmail(rs.getString("email"));
                    emp.setSalary(rs.getString("salary"));
                    list.add(emp);
                }
            }catch (SQLException e){
                throw new RuntimeException(e);
            }finally {
                closeAll(conn,pstmt,rs);
            }
            return list;
        }
}
